package com.l.web.master.webcontent;

import org.bson.types.ObjectId;
import org.l.qiao.Cluster;
import org.l.qiao.KeyType;
import org.l.qiao.Validate;
import org.l.qiao.annotation.Key;
import org.l.qiao.base.LType;

import java.util.Map;

public class WebContent extends Cluster {

    /**
     * 栏目ID
     */
    @Key(keyType = KeyType.MapKey, valueType = LType.LTYPE_STRING, check = Validate.OBJECTID + "|^$", nullable = true)
    public static final String WEB_NODE_ID = "webNodeId";

    /**
     * 标题
     */
    @Key(keyType = KeyType.MapKey, valueType = LType.LTYPE_STRING, check = "^.{1,50}$", nullable = false)
    public static final String TITLE = "title";

    /**
     * 创建者
     */
    public static final String Creator = "creator";

    public WebContent() {
        super();
    }

    public WebContent(Map<String, Object> map) {
        super(map);
    }

    public void initWebNodeId() {
        if (containsKey(WEB_NODE_ID)) {
            String webNodeid = getString(WEB_NODE_ID, "");

            if ("".equals(webNodeid)) {
                remove(WEB_NODE_ID);
            } else {
                put(WEB_NODE_ID, new ObjectId(webNodeid));
            }
        }
    }

    public boolean checkput(String key, String value) {
        if (value != null && value.length() > 0) {
            put(key, value);
            return true;
        } else {
            return false;
        }
    }
}
